import time

from selenium.webdriver.common.by import By

from Page.page_register import PageRegister
from Tools.tools import DriverTools
from config import PATH, BASE_URL, PHONE
from script import log


class TestRegister(object):
    def setup_method(self):
        # 打开浏览器
        self.driver = DriverTools.get_driver()
        # 输入网址
        DriverTools.get_driver().get(BASE_URL+"/common/member/reg")
        # 找元素，填数据
        self.reg = PageRegister(self.driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.close_driver()

    def test01_register_success(self):
        self.reg.register(PHONE, "test123456", "8888")
        time.sleep(2)
        # 打印结果
        result=self.reg.assert_register_success()
        log.info(f"执行结果{result}")
        assert "注册成功" in result
    #     截图
        self.reg.get_shot("register_success.png")

    def test02_register_fail_phone_exist(self):
        self.reg.register('18738142070', "test123456", "8888")
        time.sleep(2)
        result2 = self.reg.assert_register_fail()
        log.info(f"执行结果{result2}")
        assert "注册抢88现金" in result2
        # 截图
        self.reg.get_shot("phone_error.png")
    def test03_register_fail_pwd_num(self):
        self.reg.register('18738142070', "1234568888", "8888")
        time.sleep(2)
        result3 = self.reg.assert_register_fail()
        log.info(f"执行结果{result3}")
        assert "注册抢88现金" in result3
        # 截图
        # self.driver.get_screenshot_as_file(PATH+r"/img/pwd_error.png")
        self.reg.get_shot("pwd_error.png")